package com.ruoyi.money.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.enums.FeeAndRepairStatus;
import com.ruoyi.community.domain.CommunityFee;
import com.ruoyi.community.mapper.CommunityFeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.money.mapper.CommunityPaymentMapper;
import com.ruoyi.money.domain.CommunityPayment;
import com.ruoyi.money.service.ICommunityPaymentService;

/**
 * 在线缴费Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-18
 */
@Service
public class CommunityPaymentServiceImpl implements ICommunityPaymentService
{
    @Autowired
    private CommunityPaymentMapper communityPaymentMapper;
    @Autowired
    private CommunityFeeMapper communityFeeMapper;
    /**
     * 查询在线缴费
     *
     * @param id 在线缴费主键
     * @return 在线缴费
     */
    @Override
    public CommunityPayment selectCommunityPaymentById(Long id)
    {
        return communityPaymentMapper.selectCommunityPaymentById(id);
    }

    /**
     * 查询在线缴费列表
     *
     * @param communityPayment 在线缴费
     * @return 在线缴费
     */
    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    public List<CommunityPayment> selectCommunityPaymentList(CommunityPayment communityPayment)
    {
        return communityPaymentMapper.selectCommunityPaymentList(communityPayment);
    }

    /**
     * 新增在线缴费
     *
     * @param communityPayment 在线缴费
     * @return 结果
     */
    @Override
    public int insertCommunityPayment(CommunityPayment communityPayment)
    {
        return communityPaymentMapper.insertCommunityPayment(communityPayment);
    }

    /**
     * 修改在线缴费
     *
     * @param communityPayment 在线缴费，查询缴费情况
     * @return 结果
     */
    @Override
    public int updateCommunityPayment(CommunityPayment communityPayment)
    {
        //查询用户缴费情况并作状态修改和设置缴费时间
        CommunityFee communityFee = communityFeeMapper.selectCommunityFeeById(communityPayment.getId());
        communityFee.setStatus(FeeAndRepairStatus.OK.getCode());
        communityFee.setDate(new Date());
        communityFeeMapper.updateCommunityFee(communityFee);
        return communityPaymentMapper.insertCommunityPayment(communityPayment);
    }

    /**
     * 批量删除在线缴费
     *
     * @param ids 需要删除的在线缴费主键
     * @return 结果
     */
    @Override
    public int deleteCommunityPaymentByIds(Long[] ids)
    {
        return communityPaymentMapper.deleteCommunityPaymentByIds(ids);
    }

    /**
     * 删除在线缴费信息
     *
     * @param id 在线缴费主键
     * @return 结果
     */
    @Override
    public int deleteCommunityPaymentById(Long id)
    {
        return communityPaymentMapper.deleteCommunityPaymentById(id);
    }
}
